/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prft.rms.jsf;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.prft.rms.entity.Employee;
import com.prft.rms.service.EmployeeService;

/**
 * 
 * @author cairns.ma
 */
public class EmployeeListAction {

	Logger logger = LoggerFactory.getLogger(EmployeeListAction.class);
	private EmployeeService employeeService;
	private List<Employee> employeeList;
	private boolean descending = true;
	private boolean oldDescending = descending;
	private String columnName = "emid";
	private String oldColumnName = columnName;

	private EmployeeListDateModel employeeDateModel;

	/** Creates a new instance of EmployeeListAction */
	public EmployeeListAction() {
		logger.debug("get new instance");
	}

	public EmployeeListDateModel getEmployeeDateModel() {
		logger.debug("invoke getEmployeeDateModel "+ this.toString());
		
		return employeeDateModel;
	}

	public void setEmployeeDateModel(EmployeeListDateModel employeeDateModel) {
		this.employeeDateModel = employeeDateModel;
	}

	/**
	 * @return the employeeList
	 */
	public List<Employee> getEmployeeList() {
		logger.debug("invoke get employee");
		if (employeeList == null) {
			init();
		} else if ((descending != oldDescending) || (!columnName.equals(oldColumnName))) {
			init();
			// reset dirty flags.
			oldDescending = descending;
			oldColumnName = columnName;
		}
		return employeeList;
	}

	/**
	 * @return the employeeService
	 */
	public EmployeeService getEmployeeService() {
		return employeeService;
	}

	/**
	 * @param employeeService
	 *            the employeeService to set
	 */
	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	public boolean isDescending() {
		return descending;
	}

	public void setDescending(boolean descending) {
		logger.debug("change descending");
		oldDescending = this.descending;
		this.descending = descending;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		logger.debug("change sorte column");
		logger.debug(this.toString());
		oldColumnName = this.columnName;
		this.columnName = columnName;
	}

	private void init() {
		//employeeList = getEmployeeService().getSortedEmployees(columnName, descending);
	}

}
